package com.sqx.modules.user.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sqx.common.utils.PageUtils;
import com.sqx.common.utils.Result;
import com.sqx.modules.app.annotation.Login;
import com.sqx.modules.app.entity.UserEntity;
import com.sqx.modules.app.service.UserService;
import com.sqx.modules.datacentre.entity.SysUserShop;
import com.sqx.modules.pay.service.CashOutService;
import com.sqx.modules.sys.controller.AbstractController;
import com.sqx.modules.sys.entity.SysUserEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = {"用户端-用户钱包"})
@RestController
@RequestMapping("/app/userMoney/")
public class UserShopMoneyController extends AbstractController {
    @Autowired
    CashOutService cashOutService;
    @Autowired
    UserService userService;

    @RequestMapping(value = "selectCashOutList", method = RequestMethod.GET)
    @ApiOperation("查询提现记录列表")
    @ResponseBody
    @Login
    public Result selectHelpProfit(int page, int limit,@RequestAttribute("userId") Long userId) {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("limit", limit);
        UserEntity user = userService.selectUserById(userId);
        map.put("userId", user.getUserId());
        PageUtils pageUtils = cashOutService.selectCashOutList(map);
        return Result.success().put("data", pageUtils);
    }
    @Login
    @GetMapping("info")
    public Result info(@RequestAttribute("userId") Long userId) {
        UserEntity userEntity = userService.selectUserById(userId);
        return Result.success().put("data", userEntity);
    }

    @Login
    @RequestMapping(value = "updateUser", method = RequestMethod.POST)
    @ApiOperation("修改当前登录用户的提现信息")
    public Result updateUser(@RequestAttribute("userId") Long userId,@RequestBody UserEntity userEntity) {
        userEntity.setUserId(userId);
        userService.updateById(userEntity);
        return Result.success();
    }
    @Login
    @GetMapping(value = "userCashMoney")
    @ApiOperation("用户发起提现")
    public Result shopCashMoney(Double money, Integer classify,@RequestAttribute("userId") Long userId) {
        UserEntity userEntity =userService.selectUserById(userId);

        return cashOutService.cashMoney(userEntity.getUserId(),null,money,classify, 1);
    }
    @Login
    @GetMapping(value = "shopBindingQrCode")
    @ApiOperation("商户绑定提现二维码")
    public Result shopBindingQrCode(String cashQrCode,@RequestAttribute("userId") Long userId){
        UserEntity user = userService.selectUserById(userId);
        user.setCashQrCode(cashQrCode);
        userService.updateById(user);
        return Result.success();
    }
}
